<?php

Header("content-type: application/x-javascript");

//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages() {
    
    $curimage=0;
    $files = array();
    $connection = mysqli_connect('localhost','root','','tripviet') or die('Could not connect to DB');
    $sql = "SELECT id,name,path FROM gallery";       
            $result = mysqli_query($connection,$sql) or die('Could not select email '.mysqli_error($connect));
            while($set = mysqli_fetch_array($result, MYSQLI_ASSOC)) {               
                $sPath = $set['path'];
                echo 'galleryarray['.$curimage.']="'.$sPath .'";';
                $curimage++;
            }
            return($files);
}

echo 'var galleryarray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
